/** 根据类内的某一个属性作为锁属性 */
export const autoLock =
    (lock: string | string[]) => (target: any, prop: string) => {
        const old: any = target[prop];
        if (typeof lock === "string") {
            target[prop] = (...args: any[]) => {
                if (target[lock]) return false;
                target[lock] = true;
                return old.apply(target, args);
            };
        } else {
            // 功能：使用数组表示对象解构的引用
            //! 未被验证
            const [last, Value] = lock.reduce(
                ([_, newOne], cur) => {
                    return [newOne, newOne[cur]];
                },
                [null, target] as [any, any]
            );
            target[prop] = (...args: any[]) => {
                if (Value) return false;
                const tail = lock[lock.length - 1];
                const Last = last!;
                Last[tail] = true;
                return old.apply(target, args);
            };
        }
    };
